package edu.zju.gis.dldsj.service.impl;

import edu.zju.gis.dldsj.dao.RoleFunctionMapper;
import edu.zju.gis.dldsj.entity.RoleFunction;
import edu.zju.gis.dldsj.service.RoleFunctionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * @author yanlo yanlong_lee@qq.com
 * @version 1.0 2018/08/09
 */
@Service
public class RoleFunctionServiceImpl implements RoleFunctionService {
    @Autowired
    private RoleFunctionMapper roleFunctionMapper;

    @Override
    public RoleFunction select(String pk) {
        return roleFunctionMapper.selectByPrimaryKey(pk);
    }

    @Override
    public int insert(RoleFunction roleFunction) {
        return roleFunctionMapper.insertSelective(roleFunction);
    }

    @Override
    public void update(RoleFunction roleFunction) {
        roleFunctionMapper.updateByPrimaryKeySelective(roleFunction);
    }

    @Override
    public void delete(String s) {
        roleFunctionMapper.deleteByPrimaryKey(s);
    }

    @Override
    public boolean isExist(String s) {
        return roleFunctionMapper.selectByPrimaryKey(s) != null;
    }

    @Override
    public List<RoleFunction> getByPage(int offset, int size) {
        return roleFunctionMapper.selectByPage(offset, size);
    }

    @Override
    public void save(@NotNull List<RoleFunction> functions) {
        functions.forEach(roleFunctionMapper::insertSelective);
    }

    @Override
    public void update(@NotNull List<RoleFunction> functions) {
        functions.forEach(roleFunctionMapper::updateByPrimaryKeySelective);
    }

    @Override
    public void deleteByRoleId(String roleId) {
        roleFunctionMapper.deleteByRoleId(roleId);
    }

    @Override
    public void delete(String roleId, String functionId) {
        roleFunctionMapper.delete(roleId, functionId);
    }

    @Override
    public boolean exist(String roleId, String functionId) {
        return roleFunctionMapper.select(roleId, functionId) != null;
    }

    @Override
    public List<RoleFunction> selectByRoleId(String roleId) {
        return roleFunctionMapper.selectByRoleId(roleId);
    }
}
